class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new
    if user.new_record?
      cannot :manage, :all
    elsif user.admin?
      can :manage, :all
    else
      user.permissions.each do |per|
        can per.ability, Object.const_get(per.class_name.classify)
      end
    end
  end
end